package com.example.bilibili_fake.ui.splash

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.ImageView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.ViewModelProvider
import com.bumptech.glide.Glide
import com.example.bilibili_fake.MainActivity
import com.example.bilibili_fake.R
import com.example.bilibili_fake.databinding.ActivitySplashBinding
import com.example.bilibili_fake.utils.LogUtil
import com.example.bilibili_fake.viewmodel.SplashViewModel

class SplashActivity : AppCompatActivity() {
    private lateinit var binding: ActivitySplashBinding
    private lateinit var viewModel: SplashViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySplashBinding.inflate(layoutInflater)
        setContentView(binding.root)

        viewModel = ViewModelProvider(this)[SplashViewModel::class.java]

        loadSplashImage()

        // 延迟跳转到主界面
        Handler(Looper.getMainLooper()).postDelayed({
            startActivity(Intent(this, MainActivity::class.java))
            finish()
        }, 3000) // 建议增加延迟时间到3秒
    }

    private fun loadSplashImage() {
        viewModel.splashImageUrls.firstOrNull()?.let { imageUrl ->
            Glide.with(this)
                .load(imageUrl)
                .centerCrop()
                .into(binding.splashImageView)
        }
    }
}

